package com.baway.biliclitent.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.baway.biliclitent.R;
import com.baway.biliclitent.model.RegionBean;

import java.util.List;

/**
 * Created by dell on 2017/3/10.
 */

public class RegionTypeRecommendAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private RegionBean.DataBeanHeadline data;
    private final int TYPE_RECOMMEND = 1;
    private final int TYPE_NEW = 2;
    public RegionTypeRecommendAdapter(Context context, RegionBean.DataBeanHeadline data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        if(viewType == TYPE_RECOMMEND){
            view = LayoutInflater.from(context).inflate(R.layout.region_recommend_item,parent,false);
            return new ViewHolder(view);
        }else {
            view = LayoutInflater.from(context).inflate(R.layout.region_recommend_item,parent,false);
            return new ViewHolder2(view);
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof ViewHolder){
            ViewHolder holder1 = (ViewHolder) holder;
            holder1.textView.setText("最热视频");
            List<RegionBean.DataBeanHeadline.RecommendBeanHeadline> recommend =
                    data.getRecommend();
            RegionListAdapter listAdapter = new RegionListAdapter(context,recommend);
           holder1.listView.setAdapter(listAdapter);
        }else {
            ViewHolder2 holder2 = (ViewHolder2) holder;
            holder2.textView.setText("最新视频");
            List<RegionBean.DataBeanHeadline.NewBeanHeadline> newX = data.getNewX();
            RegionListBottomAdapter listBottomAdapter = new RegionListBottomAdapter(context,newX);
            holder2.listView.setAdapter(listBottomAdapter);
        }
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        if(position == 0){
            return TYPE_RECOMMEND;
        }else {
            return TYPE_NEW;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        ListView listView;
        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.region_recommend_nameTv);
            listView = (ListView) itemView.findViewById(R.id.region_recommend_lv);
        }
    }
    class ViewHolder2 extends RecyclerView.ViewHolder{
        TextView textView;
        ListView listView;
        public ViewHolder2(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.region_recommend_nameTv);
            listView = (ListView) itemView.findViewById(R.id.region_recommend_lv);
        }
    }
}
